//
//  GXHistoryDailyTableViewCell.m
//  GXLanOuADemo
//
//  Created by 甘霞 on 15/11/4.
//  Copyright © 2015年 甘霞. All rights reserved.
//

#import "GXHistoryDailyTableViewCell.h"
#import "GXDailyModel.h"

//#define kSideBorder 20
#define kWidth self.contentView.frame.size.width

@interface GXHistoryDailyTableViewCell ()

@property (nonatomic, retain) UILabel *dateLabel;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UILabel *descLabel;

@end

@implementation GXHistoryDailyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    
    BOOL isNight = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"];
    self.backgroundColor = isNight ? [UIColor blackColor] : [UIColor whiteColor];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeModel) name:@"changeModel" object:nil];
    
    //日期
    self.dateLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.dateLabel];
    [self.dateLabel setTextAlignment:NSTextAlignmentCenter];
    self.dateLabel.textColor = isNight ? [UIColor whiteColor] : [UIColor blackColor];
    [self.dateLabel setFont:[UIFont fontWithName:@"AmericanTypewriter-Bold" size:25]];
    //标题
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.textColor = isNight ? [UIColor whiteColor] : [UIColor blackColor];
    [self.titleLabel setFont:[UIFont fontWithName:@"AmericanTypewriter-CondensedBold" size:20]];
    [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
    //简介
    self.descLabel = [[UILabel alloc] init];
    [self.descLabel setTextAlignment:NSTextAlignmentCenter];
    self.descLabel.textColor = isNight ? [UIColor whiteColor] : [UIColor blackColor];
    [self.descLabel setFont:[UIFont fontWithName:@"AppleSDGothicNeo-Bold" size:17]];
    [self.descLabel setNumberOfLines:3];
    [self.contentView addSubview:self.descLabel];
}

- (void)changeModel {
    BOOL isNight = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"];
    self.backgroundColor = isNight ? [UIColor blackColor] : [UIColor whiteColor];
    self.dateLabel.textColor = isNight ? [UIColor whiteColor] : [UIColor blackColor];
    self.titleLabel.textColor = isNight ? [UIColor whiteColor] : [UIColor blackColor];
    self.descLabel.textColor = isNight ? [UIColor whiteColor] : [UIColor blackColor];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    //日期
    [self.dateLabel setFrame:CGRectMake(0, kSideBorder, kWidth, 20)];
    //标题
    [self.titleLabel setFrame:CGRectMake(0, CGRectGetMaxY(self.dateLabel.frame) + 10, kWidth, 20)];
    //简介
    [self.descLabel setFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame) + 10, kWidth, 80)];
}

- (void)setDailyModel:(GXDailyModel *)dailyModel {
    if (_dailyModel != dailyModel) {
        _dailyModel = dailyModel;
    }
    self.dateLabel.text = _dailyModel.release_date;
    self.titleLabel.text = _dailyModel.title;
    self.descLabel.text = _dailyModel.intro;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
